package cn.minhx.types.design.tree;

/**
 * 策略路由抽象类
 *
 * @author minhx
 */
public abstract class AbstractStrategyRouter<T, D, R> implements StrategyMapper<T, D, R>, StrategyHandler<T, D, R> {

	protected StrategyHandler<T, D, R> defaultStrategyHandler = StrategyHandler.DEFAULT;

	public R router(T requestParameter, D dynamicContext) throws Exception {
		StrategyHandler<T, D, R> strategyHandler = next(requestParameter, dynamicContext);
		if (null != strategyHandler) {
			return strategyHandler.apply(requestParameter, dynamicContext);
		}
		return defaultStrategyHandler.apply(requestParameter, dynamicContext);
	}
}
